package com.itsenpupulai.bdtest.app;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.SDKInitializer;
import com.itsenpupulai.bdtest.bean.DaoMaster;
import com.itsenpupulai.bdtest.bean.DaoSession;
import com.itsenpupulai.bdtest.listener.MyLocationListener;


/**
 * Created by Administrator on 2017/5/9.
 */

public class MyApp extends Application {
//    public static final boolean ENCRYPTED = true;

    private static DaoSession daoSession;
    public static LocationClient mLocationClient ;


    @Override
    public void onCreate() {
        super.onCreate();
        SDKInitializer.initialize(getApplicationContext());
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "user.db" , null);
        SQLiteDatabase db = helper.getWritableDatabase();
        daoSession = new DaoMaster(db).newSession();
        mLocationClient = new LocationClient(getApplicationContext());
        mLocationClient.registerLocationListener(new MyLocationListener());
        InitLocation();
    }

    public static DaoSession getDaoSession() {
        return daoSession;
    }
    public static void InitLocation() {
        // // 地图初始化
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);// 设置定位模式
        option.setCoorType("bd09ll");// 返回的定位结果是百度经纬度，默认值gcj02 bd09ll
        option.setScanSpan(0);// 设置发起定位请求的间隔时间, 0 为只请求一次
        option.setIsNeedAddress(true);// 需要城市、街道等信息
        option.setOpenGps(true);

        mLocationClient.setLocOption(option);
        mLocationClient.start();
    }
}
